// pages/shopManager/shopExclusive/orderDetail/orderDetail.js
const common = require('../../../../utils/util.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orderId: null,
        orderInfo: null,
        roleList: ['无', '普通会员', '会员']
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            orderId: options.orderId
        })
        this.getOrderInfo()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.setData({
            orderInfo: null
        })
        this.getOrderInfo()
        setTimeout(function() {
            wx.stopPullDownRefresh()
        }, 2000)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    getOrderInfo: function() {
        const that = this
        let data = {
            order_id: this.data.orderId,
            is_goods: 8,
            get_user: 1,
            paramter: 1
        }
        common.post('Orderlist/user_order', data).then(function(res) {
            if (res.code == 204) {
                return
            } else {
                that.setData({
                    orderInfo: res[0]
                })
            }
        }).catch(function(e) {})
    },

    goConfirm: function(e) {
        const that = this
        wx.showModal({
            title: '提示',
            content: '是否确认领取？',
            success(res) {
                if (res.confirm) {
                    wx.showLoading({
                        title: '请稍后'
                    })
                    let data = {
                        order_id: e.currentTarget.dataset.id
                    }
                    common.post('Orderlist/store_affirm_order', data).then(function(res) {
                        wx.hideLoading()
                        if (res.code == 204) {
                            wx.showModal({
                                title: '提示',
                                content: res.error,
                                showCancel: false,
                                success(res) {}
                            })
                            return
                        }
                        wx.showModal({
                            title: '提示',
                            content: '成功确认领取',
                            showCancel: false,
                            success(res) {
                                if (res.confirm) {
                                    wx.navigateBack({
                                        delta: 1
                                    })
                                }
                            }
                        })
                    }).catch(function(e) {})
                }
            }
        })
    },

    phoneCall: function(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone
        })
    }
})